package com.data.unityplugin_market.viewmodel

import android.app.Instrumentation
import android.databinding.ObservableField
import com.data.unityplugin_market.base.BaseVM
import com.data.unityplugin_market.network.NetWorkConfig

public class ShoppingCartItemVM : BaseVM(){
    /**
     * 选中状态
     */
    var checkStatus  = ObservableField<Boolean>(false)

    /**
     * 单件商品总数
     */
    var goodsTotal = ObservableField<String>("1");

    /*
     * 商品图片
     */
    var goodsImageUrl = ObservableField<String>();
    /*
     * 商品价格
     */
    var goodsPrice = ObservableField<String>("1")

    /*
     * 商品描述
     */
    var goodsDescription = ObservableField<String>()

    /**
     * 商品型号
     */
    var goodsModel = ObservableField<String>()

    /**
     * 图片资源
     */
    var imageUrl = ObservableField<String>()

    var isModify = ObservableField<Boolean>()

    /**
     * 商品ID
     */
    var goodsID = ObservableField<String>()

    /**
     * 商品的itemID
     */
    var itemID = ObservableField<String>();

    var listener : OnItemModifyClick ? = null

     interface OnItemModifyClick{
        fun onModify(vm : ShoppingCartItemVM)
    }


    fun addCount(){
        updateCount(true)
        listener?.onModify(this)
    }

    fun reduceCount(){
        updateCount(false)
        listener?.onModify(this)
    }



    private fun updateCount(isAdd : Boolean){
        var tmp = Integer.parseInt(goodsTotal.get())
        if (isAdd) {
            tmp += 1;
        } else {
            if (tmp > 1)
                tmp -= 1
        }
        goodsTotal.set(tmp.toString())
    }



}